package me.zhengjie.modules.weChat.service.impl;

import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.security.config.SecurityProperties;
import me.zhengjie.modules.weChat.service.WXService;
import me.zhengjie.utils.RedisUtils;

import org.springframework.stereotype.Service;

@Service
@Slf4j
public class WXServiceImpl implements WXService {

    private final SecurityProperties properties;
    private RedisUtils redisUtils;

    public WXServiceImpl(SecurityProperties properties, RedisUtils redisUtils) {
        this.properties = properties;
        this.redisUtils = redisUtils;
    }

    @Override
    public void saveOpenIdToken(String token, String openid) {
        redisUtils.set(openid, token, properties.getTokenValidityInSeconds()/1000);
    }

    @Override
    public String getByOpenId(String openid) {
        String token= (String) redisUtils.get(openid);
        return token;
    }
}
